// import Vue from 'vue'
const subject = {
	namespaced: true,
	state: {
		// 带分页题目的对象
		pageSubjects: [],
		// 缓存题目答案
		cacheSubjectsOptions: {},
		// 缓存乱序后的选项
		cacheOrderOptions: {}
	},
	mutations: {
		updatePageSubjects(state, pageSubjects) {
			state.pageSubjects = pageSubjects
		},
		updateSubject(state, subject) {
			const index = state.pageSubjects[subject.PAGE_NUMBER - 1].subjects.findIndex(s => s.SUBJECT_ID ==
				subject
				.SUBJECT_ID)
				state.pageSubjects[subject.PAGE_NUMBER - 1].subjects[index] = subject
			// Vue.set(state.pageSubjects[subject.PAGE_NUMBER - 1].subjects, index, subject)
		},
		setCacheSubjectsOption: (state, obj) => {
			state.cacheSubjectsOptions[obj.subject_id] = obj.value;
		},
		clearSubjectsOptions(state) {
			state.cacheSubjectsOptions = {}
		},
		setCacheOrderOptions: (state, obj) => {
			state.cacheOrderOptions[obj.subject_id] = obj.value;
		},
		updatePageShow(state, index) {
			state.pageSubjects.forEach(p => p.show = false)
			state.pageSubjects[index].show = true
		}
	},
	actions: {
		updatePageSubjects({
			commit
		}, pageSubjects) {
			commit('updatePageSubjects', pageSubjects)
		},
		updateSubject({
			commit
		}, subject) {
			commit('updateSubject', subject)
		},
		updateCacheSubjectsOption({
			commit
		}, obj) {
			commit('setCacheSubjectsOption', obj)
		},
		clearSubjectsOptions({
			commit
		}) {
			commit('clearSubjectsOptions')
		},
		updateCacheOrderOptions({
			commit
		}, obj) {
			commit('setCacheOrderOptions', obj)
		},
		updatePageShow({
			commit
		}, index) {
			commit('updatePageShow', index)
		}
	}
}

export default subject;